let baseUrl = 'https://apifoxmock.com/m1/4728220-0-default/api'

export default function http(url, data = {}, method = 'get') {
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseUrl + url, // 假设服务器地址前缀为https://example.com
            data,
            method,
            header: {
                //  'Content-Type': 'application/json',
                'token': uni.getStorageSync('token') || ''
            },
            success: (res) => {
                if (res.statusCode === 200) {
                    if (res.data.code == 1) {
                        resolve(res.data);
                    } else if (res.data.code === 0) {
                        uni.showToast({
                            title: res.data.msg || '请求失败！',
                            icon: 'none'
                        })
                        reject(res.data.msg)
                    }
                } else {
                    reject(new Error('请求失败，状态码：' + res.statusCode));
                }
            },
            fail: (err) => {
                uni.showToast({
                    title: '服务器请求异常！',
                    icon: 'none'
                })
            }
        })
    })

}